const state = {
  openId: '',
  token: '',
  headImgUrl: '',
  userInfo: '',
  userType: ''
}

const getters = {

}

const actions = {
  setOpenId (context, openId) {
    localStorage.setItem('openId', openId)
    context.commit('stageOpenId', openId)
  },
  setToken (context, token) {
    if (token !== null && token !== undefined && token != '') {
      localStorage.setItem('token', token)
      context.commit('stageToken', token)
    }
  },
  setHeadImgUrl (context, headImgUrl) {
    context.commit('stageHeadImgUrl', headImgUrl)
  },
  setUserInfo (context, userInfo) {
    context.commit('stageUserInfo', userInfo)
  },
  setUserType (context, userType) {
    context.commit('stageUserType', userType)
  }
}

const mutations = {
  stageOpenId (state, openId) {
    state.openId = openId
  },
  stageToken (state, token) {
    state.token = token
  },
  stageHeadImgUrl (state, headImgUrl) {
    state.headImgUrl = headImgUrl
  },
  stageUserInfo (state, userInfo) {
    state.userInfo = userInfo
  },
  stageUserType (state, userType) {
    state.userType = userType
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}